package com.ascainiao3d.display
{
	import flash.display.Sprite;
	
	public class World3D extends Sprite
	{
		private var fl:Number = 250;
		//消失点
		private var vpX:Number;
		private var vpY:Number;
		//子对象列表
		private var _childList:Vector.<Object3D>;
		//灯光
		private var _light:Light = new Light(0,0,-100);
		public function World3D(vpx:Number,vpy:Number)
		{
			super();
			vpX=vpx;
			vpY=vpy;
			_childList=new Vector.<Object3D>();
		}
		public function addObject3D(obj:Object3D):void{
			if(_childList.indexOf(obj)==-1){
				_childList.push(obj);
				obj.setVariable(_light,vpX,vpY,0,0,200);
			}
		}
		
		public function rendering():void{
			this.graphics.clear();
			_childList.sort(compare);
			//_childList.sort(comparex);
			//_childList.sort(comparey);
			//sort(_childList);
			for (var i:uint = 0; i < _childList.length; i++)
			{//trace(_childList[i].z)
				_childList[i].draw(graphics);
			}
		}

		public function get light():Light
		{
			return _light;
		}

		public function set light(value:Light):void
		{
			_light = value;
		}
		
		/**
		 * 排序，按照空间深度排列
		 * @param x
		 * @param y
		 * @return 
		 * 
		 */		
		private function compare(a:Object3D, b:Object3D):Number {
			if(a.z<b.z){
				return 1;
			}else if(a.z>b.z){
				return -1;
			}else{
				return 0;
			}
		}
	}
}